define(function (require, exports, module) {


    function onload() {
        /**
         * 计算不通层级下两点之间的像素
         *
         * @param fromPointCoordinate 起点坐标
         * @param toPointCoordinate   终点坐标
         * @param zoomLevel 层级
         * @returns {number}
         */
        const getPixelBetweenTowPointsWithZoom = (fromPointCoordinate, toPointCoordinate, zoomLevel) => {
            const from = turf.point(fromPointCoordinate)
            const to = turf.point(toPointCoordinate)
            const options = { units: 'kilometers' }
            // 每像素多少米, 详见: https://docs.mapbox.com/help/glossary/zoom-level
            let metersOfEveryPixel
            if (zoomLevel < 1) {
                metersOfEveryPixel = 59959.436
            } else if (zoomLevel < 2) {
                metersOfEveryPixel = 29979.718
            } else if (zoomLevel < 3) {
                metersOfEveryPixel = 14989.859
            } else if (zoomLevel < 4) {
                metersOfEveryPixel = 7494.929
            } else if (zoomLevel < 5) {
                metersOfEveryPixel = 3747.465
            } else if (zoomLevel < 6) {
                metersOfEveryPixel = 1873.732
            } else if (zoomLevel < 7) {
                metersOfEveryPixel = 936.866
            } else if (zoomLevel < 8) {
                metersOfEveryPixel = 468.433
            } else if (zoomLevel < 9) {
                metersOfEveryPixel = 234.217
            } else if (zoomLevel < 10) {
                metersOfEveryPixel = 117.108
            } else if (zoomLevel < 11) {
                metersOfEveryPixel = 58.554
            } else if (zoomLevel < 12) {
                metersOfEveryPixel = 29.277
            } else if (zoomLevel < 13) {
                metersOfEveryPixel = 14.639
            } else if (zoomLevel < 14) {
                metersOfEveryPixel = 7.319
            } else if (zoomLevel < 15) {
                metersOfEveryPixel = 3.660
            } else if (zoomLevel < 16) {
                metersOfEveryPixel = 1.830
            } else if (zoomLevel < 17) {
                metersOfEveryPixel = 0.915
            } else if (zoomLevel < 18) {
                metersOfEveryPixel = 0.457
            } else if (zoomLevel < 19) {
                metersOfEveryPixel = 0.229
            } else if (zoomLevel < 20) {
                metersOfEveryPixel = 0.114
            } else if (zoomLevel < 21) {
                metersOfEveryPixel = 0.057
            } else if (zoomLevel < 22) {
                metersOfEveryPixel = 0.029
            } else {
                metersOfEveryPixel = 0.014
            }
            return parseFloat((turf.distance(from, to, options) * 1000 / metersOfEveryPixel).toFixed(2))
        }

        return {
            getPixelBetweenTowPointsWithZoom
        }
    }

    module.exports = {
        onload
    }
});
